package cn.itcast.a_query;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.junit.Test;


/**
 * 作者  Administrator
 * 时间  2017/2/23 13:06
 * 文件  Hibernate35HQL
 * 描述
 */
public class App_save {
	private static  SessionFactory sf;

	static {
		sf = new org.hibernate.cfg.Configuration().configure()
				.addClass(Dept.class)
				.addClass(Employee.class)
				.buildSessionFactory();
	}

	@Test
	public void test_save(){
		Session session = sf.getCurrentSession();
		session.beginTransaction();
		Employee employee = new Employee();
		employee.setEmpName("格锅");
		Dept dept = new Dept();
		dept.setDeptName("测试部门");
		dept.getEmps().add(employee);

		session.save(dept);

		session.getTransaction().commit();

		session.close();
	}
}
